<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="home/public/head::head(~{::title},~{::style},~{})">
    <title>新闻转发-新闻管理系统</title>
    <style>
        img {
            width: 30%;
        }

        .img-thumbnail {
            height: 150px;
            width: auto;
        }
    </style>
</head>

<body>

<!--顶部导航栏-->
<div th:replace="home/public/top-menu::top-menu"></div>

<div class="layui-container" id="container" style="min-height: 590px">
    <div class="layui-row">
        <div class="layui-col-md12">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>新闻转发</legend>
            </fieldset>

            <div style="padding: 20px; background-color: #F2F2F2;">
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md12">
                        <form class="layui-form layui-form-pane" id="form" enctype="multipart/form-data">
                            <input type="hidden" name="id" th:value="${news.id}"/>
                            <input type="hidden" name="field1" th:value="${news.field1}"/>
                            <input type="hidden" name="field2" th:value="${news.field2}"/>
                            <input type="hidden" name="field3" th:value="${news.field3}"/>
                            <input type="hidden" name="field4" th:value="${news.field4}"/>
                            <div class="layui-form-item">
                                <label for="categoryId" class="layui-form-label">
                                    新闻分类
                                </label>
                                <div class="layui-input-inline" style="width: 88%;z-index: 9999">
                                    <select lay-verify="required"  name="categoryId" id="categoryId" th:placeholder="请选择分类">
                                        <option th:selected="${news.categoryId==category.id}"  th:each="category:${categoryList}" th:value="${category.id}">[[${category.name}]]</option>
                                    </select>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label for="title" class="layui-form-label">
                                    标题
                                </label>
                                <div class="layui-input-inline" style="width: 88%;">
                                    <input  type="text" id="title" th:value="${news.title}" name="title" required lay-verify="required"
                                           placeholder="标题" autocomplete="off"  class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="theme" class="layui-form-label">
                                    主题
                                </label>
                                <div class="layui-input-inline" style="width: 88%;">
                                    <input  type="text" th:value="${news.theme}" id="theme" name="theme" required lay-verify="required"
                                           placeholder="请输入新闻主题" autocomplete="off"  class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label  class="layui-form-label">
                                    详细内容
                                </label>
                                <div class="layui-input-inline" style="width: 88%;">
                                    <textarea id="uecontainer"  name="content" style="min-height: 400px" th:text="${news.content}"></textarea>
                                </div>
                            </div>

                        </form>
                        <div class="layui-form-item">
                            <button th:if="${session.user!=null}" style="margin-left: 40%;width: 200px" class="layui-btn" lay-filter="forward" lay-submit>转发</button>
                            <button th:if="${session.user==null}" style="margin-left: 40%;width: 200px" class="layui-btn" onclick="goToLogin()"  >请先登录</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<footer th:replace="home/public/footer::footer"></footer>
<script th:src="@{/static/common/plugs/vue/vue.js}"></script>

<!-- 百度编辑器配置文件 -->
<script type="text/javascript" th:src="@{/static/common/plugs/ueditor/ueditor.config.js}"></script>
<!-- 百度编辑器编辑器源码文件 -->
<script type="text/javascript" th:src="@{/static/common/plugs/ueditor/ueditor.all.js}"></script>

<script type="text/javascript">
    var ue = UE.getEditor('uecontainer');
</script>
<!--vue相关js-->
<script th:inline="javascript">

    layui.use(['form', 'layer','upload', 'jquery', 'admin'], function () {
        var form = layui.form,
            $ = layui.jquery,
            upload = layui.upload,
            layer = layui.layer;

        //监听提交
        form.on('submit(forward)', function (data) {
            var formData = new FormData($("#form")[0]);
            $.ajax({
                url: "/home/news/forward",
                type: "post",
                data: formData,
                processData: false,
                contentType: false,
                beforeSend: function(){
                    //返回的参数item，即为当前的input DOM对象
                    index = layer.load(1,{shade: [0.3,'grey']});
                },
                success: function (res) {
                    //关闭遮罩层
                    layer.close(index);
                    if (res.success == true) {
                        layer.msg(res.msg, {icon: 1, time: 1500},function () {
                            window.location.href="/home/news/homeListPage";
                        });
                    } else {
                        layer.msg(res.msg, {icon: 2, time: 1500});
                    }
                },
                error: function (res) {
                    layer.msg(res, {icon: 2, time: 1500});
                },
                complete: function () {
                }
            });
            return false;
        });
    });
    /*layui插件模块加载结束*/
    function goToLogin() {
        window.location.href="/home/login";
    }

</script>
</body>
</html>
